package com.prs.crm.dao.cqunicom.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cqunicom.NoteEditorDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cqunicom.HighGradeExpected;
import com.prs.crm.domain.cqunicom.NoteEditor;
import com.prs.crm.domain.cqunicom.Services;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2011-3-18 上午10:37:35 简单说明
 */

public class NoteEditorDaoImpl extends BaseDaoImpl<NoteEditor> implements
		NoteEditorDao {

	@Override
	public void saveOrUpNote(NoteEditor noteEditor) {
		this.getHibernateTemplate().update(noteEditor);
	}

	@Override
	public Integer delNoteEditor() {
		return (Integer) this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
							Query query = session.createQuery("delete from NoteEditor");
							return query.executeUpdate();
				        }   
				 } );
	}

	@Override
	public List<NoteEditor> getByServicesNoteEditor(final Services servicestor) {
		 return (List<NoteEditor>) this.getHibernateTemplate().execute(
					new HibernateCallback()
					{
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(NoteEditor.class);
				        	criteria.add(Restrictions.eq("servicestor", servicestor));        	
							return criteria.list();
				 				        	
				        }
					}
			);
	}

}
